package bairui.international.console.web.controller.authority.authorization.position;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.servlet.ModelAndView;

import com.lianjing.sh.project.authority.model.domain.jpa.TB_RoleBase;
import com.lianjing.sh.project.authority.service.Service_Authority;
import com.lianjing.sh.project.authority.web.controller.authority.C_Admin_Authority_Index_Left;
import com.lianjing.sh.spring.web.controller.base.action.Action;
import com.lianjing.sh.spring.web.controller.enhance.module.context.ModuleContext;
import com.lianjing.sh.spring.web.controller.enhance.navigations.context.NavigationContext;
import com.lianjing.sh.web.security.authority.bean.structure.AuthorityDataInfoSupport;
import com.lianjing.sh.web.security.authority.bean.structure.Util_AuthorityStructure;

import bairui.international.service.Service_Position;

/**
 * @generated
 *
 * C_Authority_Authorization_Position_Authority_Show
 *
 */
@Controller
public class C_Authority_Authorization_Position_Authority_Show
 extends SC_Authority_Authorization_Position_Authority_Show 
{
	
	@Autowired @Lazy private Service_Position service_Position;
	@Autowired @Lazy private Service_Authority service_Authority;
	
	/**
	 * 显示权限
	 */
	@Action(Show.class)
	@GetMapping(Show.RequestMappingValue)
	public ModelAndView show(
		ModelMap map, HttpServletRequest request,
		NavigationContext navigationContext, ModuleContext moduleContext, 
		@PathVariable(name=Show.PathVariableName.PositionId) long positionId
	) throws Exception {
		/* 侧边栏 */
		C_Admin_Authority_Index_Left.importPage(map);
		/*
		 * 选中的权限
		 */
		List<AuthorityDataInfoSupport> selectedList = new ArrayList<>();
		this.service_Authority
			.list(
					it->it.roleBases.contains(new TB_RoleBase(positionId))
						.and(it.abandonFlag.eq(false))
				)
			.forEach(it->selectedList.add(new AuthorityDataInfoSupport(it.getId(), it.getName(), it.getComment())));
		map.put("selected", Util_AuthorityStructure.generateAuthorityTree(selectedList).values());
		map.put("removeModuleUrl", C_Authority_Authorization_Position_Authority_ModuleRemove.ModuleRemove.Operate(positionId).getUrl());
		map.put("removeActionUrl", C_Authority_Authorization_Position_Authority_ActionRemove.ActionRemove.Operate(positionId).getUrl());
		/*
		 * 选中的权限
		 */
		List<AuthorityDataInfoSupport> unSelectedList = new ArrayList<>();
		this.service_Authority
			.list(
					it->it.roleBases.contains(new TB_RoleBase(positionId)).not()
						.and(it.abandonFlag.eq(false))
				)
			.forEach(it->unSelectedList.add(new AuthorityDataInfoSupport(it.getId(), it.getName(), it.getComment())));
		map.put("unselected", Util_AuthorityStructure.generateAuthorityTree(unSelectedList).values());
		map.put("addModuleUrl", C_Authority_Authorization_Position_Authority_ModuleAdd.ModuleAdd.Operate(positionId).getUrl());
		map.put("addActionUrl", C_Authority_Authorization_Position_Authority_ActionAdd.ActionAdd.Operate(positionId).getUrl());
		/*
		 * 数据
		 */
		map.put("showActionUrl", C_Authority_Authorization_Position_Authority_ActionShow.ActionShow.Operate(positionId).getUrl());
		map.put("bean", service_Position.findById(positionId));
		return new ModelAndView("admin/authority/position/authority_position");
	}
	

}


